const fs = require('fs');
const path = require('path');

// OCR配置文件路径
const configPath = path.join(__dirname, 'src/config/ocr-config.json');

// 切换到Tesseract.js配置
const tesseractConfig = {
  serviceType: 'tesseract',
  useFallback: true,
  accessKeyId: '',
  accessKeySecret: '',
  endpoint: '',
  region: '',
  baiduApiKey: '',
  baiduSecretKey: ''
};

try {
  // 备份当前配置
  if (fs.existsSync(configPath)) {
    const backupPath = configPath + '.backup.' + Date.now();
    fs.copyFileSync(configPath, backupPath);
    console.log(`已备份当前配置到: ${backupPath}`);
  }
  
  // 写入新配置
  fs.writeFileSync(configPath, JSON.stringify(tesseractConfig, null, 2));
  console.log('已切换到Tesseract.js OCR配置');
  console.log('新配置:', tesseractConfig);
  
  console.log('\n请运行以下命令安装依赖:');
  console.log('npm install');
  console.log('\n然后重启服务器以应用新配置');
  
} catch (error) {
  console.error('配置切换失败:', error);
}